package ZY11_05;

import java.util.*;
import java.util.*;
import java.util.List;

public class Company1 implements Comparable<Staff>{
        private String namel;//名称
        private String address;//地址
        private String phone;//电话
        private String natureBusiness;//经营范围
        List<Staff> arr = new ArrayList<>();

        //String name, int age, String gender, String post, double salary, int jobNumber) {
        public Company1() {
            Staff staff01 = new Staff("张三", 35, "男", "经理", 12000, "1001");
            Staff staff02 = new Staff("李四", 25, "男", "副经理", 10000, "1002");
            Staff staff03 = new Staff("王五", 30, "男", "主管", 9000, "1003");
            arr.add(staff01);
            arr.add(staff02);
            arr.add(staff03);
        }

        public boolean addStaff(Staff staff) {
            if (arr.size() == 0) {
                arr.add(staff);
                return true;
            } else {
                for (int i = 0; i < arr.size(); i++)
                    if (arr.get(i).getJobNumber().equals(staff.getJobNumber())) {
                        return false;
                    }
                arr.add(staff);
                return true;
            }
        }

        public void showList(){
            Iterator<Staff>ir = arr.iterator();
            System.out.println("员工姓名\t员工年龄\t员工性别\t员工职务\t员工薪水\t员工工号\t");
            while (ir.hasNext()){
                Staff show = ir.next();
                System.out.print(show.toString());
            }
            System.out.println("\n**************************");
        }

        public boolean delStaff(String id){
            for (Staff s:arr) {
                if (s.getJobNumber().equals(id)){
                    arr.remove(s);
                    return true;
                }
            }
            return false;
        }

        public Staff showMaxStaff(){
            Staff staff = arr.get(0);
            for (int i=0;i<arr.size();i++){
                if (staff.getSalary()<arr.get(i).getSalary()){
                    staff = arr.get(i);
                }
            }
            return staff;
        }

        public boolean raise(String id){
            for (Staff s:arr) {
                if (s.getJobNumber().equals(id)){
                    if (compareTo(s) == 1){
                        s.setSalary(s.getSalary()+1000);
                        return true;
                    }
                }
            }
            return false;
        }
        @Override
        public int compareTo(Staff o) {
            Staff staff = arr.get(0);
            for (int i=0;i<arr.size();i++){
                if (staff.getAge()<arr.get(i).getAge()){
                    staff = arr.get(i);
                }
            }
            if (o.getAge()<staff.getAge()){
                return -1;
            }
            return 1;
        }
    }
